package com.gis.dto;

import com.gis.enums.QualityReportEnum;
import lombok.Data;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.apache.commons.lang.StringUtils.capitalize;

@Data
public class OilspillDTO {
    private Integer stationId;
    private Float petroleumClass;

    public QualityReportEnum getResult() {
        if((petroleumClass==null||petroleumClass >= 600)){
            return QualityReportEnum.STATE_HAPPENED;
        }
        return QualityReportEnum.STATE_NOHAPPEN;
    }


    public OilspillDTO setParam(String param, Float value, OilspillDTO oilspillDTO){
        String methodName = "set" + capitalize(param);
        Method method = null;
        try {
            // set函数反射时要带参数类型
            method = OilspillDTO.class.getMethod(methodName, Float.class);
            method.invoke(oilspillDTO, value);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        }
        return oilspillDTO;
    }
}
